 function banner ([string]$content){
	$line = "`n--------------------------"
	($line+"`n - "+$content+$line)
}

function menu_choose(
	[String] $title,
	[string] $action_0,
	[string[]] $choices

) { #arg is an array of strings (string 0 title, string 1 first choice...)
	write-host (banner($title))
	
	$choice = 0;
	do {
		write-host "[0] $action_0"
		for($i=0;$i -lt $choices.length;$i++) {
			write-host ("["+($i+1)+"] "+$choices[$i])
		}
		$choice = [int](Read-Host $LANG_CHOICE)
	} while(($choice -lt 0) -OR ($choice -gt ($choices.length)))
	return $choice
}


function get-vmwmi ($VMServer,$sujet) {
	$VMfilterPrefix = ($sujet.scenario_name+"%")
	$VMfilterSuffix = "%"
	$vmArray = (New-Object System.Collections.ArrayList)
	foreach($vm in $sujet.vms) {
		$vmFound = $FALSE
		$nameFilter = $VMfilterPrefix+$vm.Name+$VMfilterSuffix
		write-host (" - searching for $nameFilter on server "+$VMServer)
		$vmFound = (Get-VM $nameFilter -Server $VMServer)
		if(!$vmFound) {
			Write-Host " ---> ERROR: VM NOT FOUND $nameFilter ON SERVER $VMServer. ABORDING..." -ForegroundColor red
			$vmArray=(New-Object System.Collections.ArrayList)
			break;
		} else {
			$vmArray.Insert($vmArray.count,$vmFound)
			write-host (" --> FOUND: "+($vmFound.ElementName))
		}
	}
	return $vmArray
}

function Host-IsInactiveForSeconds 
{ 
    param( 
                $Delay = 1 
         ) 
    $counter = 0; 
    While(!$host.UI.RawUI.KeyAvailable -and ($counter++ -lt $Delay)) 
    { 
        [Threading.Thread]::Sleep(1000) 
    }
	return ($counter -gt $Delay)
} 


function StartRemote ([string] $computer = ".", [string] $cmd) {
  $path = "\\$computer\root\cimv2:Win32_Process"
  $mc = new-object System.Management.ManagementClass $path
  $result = $mc.create($cmd)
  # you can also use $mc.create($cmd, $workingDir)
  $return = $result.ReturnValue
  $procID = $result.ProcessId
  Write-Host "Return:$return, PID:$procID"
  if($return -gt 0) {
  switch($return) {
  	  2 { "Access denied" }
  	  3 { "Insufficient privilege" }
  	  8 { "Unknown failure" }
  	  9 { "Path not found" }
  	  21 { "Invalid parameter" }
  	}
  }
}

function KillRemote([string] $computer=".",[string] $processName) {
	$query = ("select * from win32_process where name='"+$processName+"'")
	$processes = get-wmiobject -computername $computer -Query $query
	if($processes) {
		$result = $processes | %{$_.Terminate()}
		foreach($process in $processes) {
			write-host (" - KILLED: "+$process.ProcessID)
		}
	}
}
